//
//  GrapDetaisViewController.m
//  Alltelevisionnews
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "GrapDetaisViewController.h"

@interface GrapDetaisViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)MBProgressHUD *hud;
@property(nonatomic, strong)NSString *str;
@property(nonatomic, strong)UITableView *myTableView;
@property(nonatomic, strong)NSMutableArray *arr;
@end

@implementation GrapDetaisViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(90 *[UIScreen mainScreen].bounds.size.width / 375.0, 10, 180, 32)];
    self.navigationItem.titleView = self.titleLabel;
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = [NSString stringWithFormat:@"--- %@ ---", self.titlestr];
    
    self.myTableView = [[UITableView alloc] init];
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view);
        make.height.equalTo(self.view);
    }];
    self.myTableView.rowHeight = 130;
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    
    if ([ZDQSingleton shareSingleton].isLongin == YES) {
        self.myTableView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.3 alpha:1];
    } else {
        self.myTableView.backgroundColor = [UIColor whiteColor];
        
    }
    
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.hud.labelText = @"正在加载";
    [self createData];
    
}

- (void)createData {
    
    [SLAFNetWorkTool cacheGetWithURL:[NSString stringWithFormat:@"http://api.3g.ifeng.com/iosNews?id=ORIGIN%@&type=list&pagesize=20&gv=4.6.5&av=0&proid=ifengnews&os=ios_8.4.1&vt=5&screen=640x960&publishid=4002&uid=00843d54db6759a6011ed5becdd59b2e5420d3fd", self.strId] cookie:nil success:^(id responseObject) {
        
//        NSLog(@"%@", responseObject[0][@"body"][@"item"][0][@"title"]);
        self.arr = [NSMutableArray array];
        self.arr = [pancel baseModelByArr:responseObject[0][@"body"][@"item"]];
//        NSLog(@"%@", self.arr);
        self.hud.hidden = YES;
        [self.myTableView reloadData];
    } failure:^(NSError *error) {
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"reuse";
    TopicPageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[TopicPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
    }
    cell.backgroundColor = [UIColor clearColor];
    pancel *panc = self.arr[indexPath.row];
    
    [cell.picImage sd_setImageWithURL:[NSURL URLWithString:panc.thumbnail]];
    cell.titleLabel.text = panc.title;
    
    cell.topicLabel.textColor = [UIColor grayColor];
    NSString *strTime = [panc.updateTime substringToIndex:10];
    cell.topicLabel.text = strTime;
    
    cell.talkLabel.textColor = [UIColor grayColor];
    cell.talkLabel.text = [NSString stringWithFormat:@"%@ 阅", panc.commentsAll];
    
    if ([ZDQSingleton shareSingleton].isLongin == YES) {
        cell.picImage.alpha = 0.4;
        cell.titleLabel.textColor = [UIColor whiteColor];
        cell.topicLabel.textColor = [UIColor whiteColor];
        cell.talkLabel.textColor = [UIColor whiteColor];
    } else {
        
        cell.picImage.alpha = 1;
        cell.titleLabel.textColor = [UIColor blackColor];
        cell.topicLabel.textColor = [UIColor grayColor];
        cell.talkLabel.textColor = [UIColor grayColor];
    }
    
    return cell;
}

#pragma mark  tableView 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    DetaisWebViewController *detaVC = [[DetaisWebViewController alloc] init];
    [self.navigationController pushViewController:detaVC animated:YES];
    detaVC.strId = [self.arr[indexPath.row] commentsUrl];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
